package org.edu.modules.sbzc.fund.service.impl;

import cn.hutool.core.convert.Convert;
import org.edu.common.base.BasePageDto;
import org.edu.common.base.BaseServiceImpl;
import org.edu.common.utils.ConvertUtils;
import org.edu.common.base.BaseServiceImpl;
import org.edu.modules.sbzc.fund.dto.VeSbzcZcAssetDto;
import org.edu.modules.sbzc.fund.enums.AssetStatusEnum;
import org.edu.modules.sbzc.fund.mapper.VeSbzcZcMaintainMapper;
import org.edu.modules.sbzc.fund.entity.VeSbzcZcMaintain;
import org.edu.modules.sbzc.fund.dto.VeSbzcZcMaintainDto;
import org.edu.modules.sbzc.fund.service.VeSbzcZcAssetService;
import org.edu.modules.sbzc.fund.service.VeSbzcZcMaintainService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;


/**
 * 实现类
 */
@Service
public class VeSbzcZcMaintainServiceImpl extends BaseServiceImpl<VeSbzcZcMaintain, VeSbzcZcMaintainMapper> implements VeSbzcZcMaintainService {

    /**
     * VeSbzcZcAssetService
     */
    @Autowired
    private VeSbzcZcAssetService veSbzcZcAssetService;

    public IPage<VeSbzcZcMaintainDto> pageDto(BasePageDto page, @Param(Constants.WRAPPER) Wrapper queryWrapper){
        return mapper.pageDto(page,queryWrapper);
    }
    /**
    * 查询实体类
    */
    public VeSbzcZcMaintainDto findDtoById(String id) {
        VeSbzcZcMaintain entity = super.findById(id);
        VeSbzcZcMaintainDto dto = ConvertUtils.convertToDto(entity, VeSbzcZcMaintainDto.class);
        return dto;
    }

    /**
    * 新增或者修改
    */
    public void insertOrUpdate(VeSbzcZcMaintainDto dto,Boolean isAdd){
        if(isAdd){
            dto.setStatus(2);
            super.insert(dto);
            //更改固资状态为维修中
            veSbzcZcAssetService.updateAssetStatus(Convert.toStr(dto.getAssetId()), AssetStatusEnum.MAINTAIN.getValue());
        }else{
            super.update(dto);
            //更改固资状态为维修完成
        };

    }

}
